#include <stdio.h>

int backtrace_xy(void **BUFFER, int SIZE)
{
	volatile int n = 0;
	volatile int *p;
	volatile int *q;
	volatile int ebp1;
	volatile int eip1;
	volatile int i = 19770;

	p = &n;

	printf("i=%d,,, 19770i =? {%d}\n", i, p[4]);
    //for(int j=0;j<64;j++)
	//	printf("p[%d] =? {0x%08x = %d}\n", j, p[j], p[j]);


	extern int main();
	extern void fun1();
	extern void fun2();
	extern void print_call();
    printf("main=%p, fun1=%p, fun2=%p, print_call=%p\n", main, fun1, fun2, print_call);

	ebp1 = p[6];
	eip1 = p[7];

	printf("= backtrace_xy addr: 0x%0x, param1: 0x%0x, param2: 0x%0x\n",
		(int)backtrace_xy,
		(int)&BUFFER,
		(int)&SIZE);

	printf("n addr is 0x%0x\n", (int)&n);
	printf("p addr is 0x%0x\n", (int)&p);

#if 1
	for (i = 0; i <SIZE; i++) {
		printf("ebp1 is 0x%0x, eip1 is 0x%0x\n", ebp1, eip1);
		BUFFER[i] = (void *)eip1;
		p = (int*)ebp1;
		q = p - 5;
		eip1 = q[5];
		ebp1 = q[2];
		if (ebp1 == 0 || eip1 == 0)
			break;
	}
#endif

	fprintf(stderr, "total level: %d\n", i);
	return i;
}
